package com.itheima.springboot_condition.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

public class UserConditional implements Condition {
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //这里的判断决定UserConFig里面的bean文件是否通过
       /* //定义一个布尔值为true
        boolean flag = true;
        //是否获取到jedis,根据获取到的数据返回布尔值
        try {
            Class<?> aClass = Class.forName("redis.clients.jedis.Jedis");
        } catch (ClassNotFoundException e) {
            return false;
        }
        return flag;*/
        //定义一个布尔值为true
        //动态获取
        boolean flag = true;
        //是否获取到jedis,根据获取到的数据返回布尔值
        Map<String, Object> attributes = annotatedTypeMetadata.getAnnotationAttributes(UserConditionalet.class.getName());
        //对应的返回值是UserConditionalet里面的返回值
        String[] value = (String[]) attributes.get("value");
        try {
            //遍历string数组
            for (String className : value) {
                //遍历到每个依赖,把这个参数放入到Class.forName方法里面
                Class<?> aClass = Class.forName(className);
            }
        } catch (ClassNotFoundException e) {
            return false;
        }
        return flag;
    }
}
